<template>
  <div class="sidebar">
    <el-menu
      class="sidebar-el-menu"
      :default-active="onRoutes"
      :collapse="collapse"
      background-color="#fff"
      text-color="black"
      active-text-color="red"
      unique-opened
      router
    >
      <template v-for="item in items">
        <template v-if="item.subs">
          <el-submenu :index="item.index" :key="item.index">
            <template slot="title">
              <i :class="item.icon"></i>
              <span slot="title">{{ item.title }}</span>
            </template>
            <template v-for="subItem in item.subs">
              <el-submenu v-if="subItem.subs" :index="subItem.index" :key="subItem.index">
                <template slot="title">{{ subItem.title }}</template>
                <el-menu-item
                  v-for="(threeItem,i) in subItem.subs"
                  :key="i"
                  :index="threeItem.index"
                >{{ threeItem.title }}</el-menu-item>
              </el-submenu>
              <el-menu-item v-else :index="subItem.index" :key="subItem.index">{{ subItem.title }}</el-menu-item>
            </template>
          </el-submenu>
        </template>
        <template v-else>
          <el-menu-item :index="item.index" :key="item.index">
            <i :class="item.icon"></i>
            <span slot="title">{{ item.title }}</span>
          </el-menu-item>
        </template>
      </template>
    </el-menu>
  </div>
</template>

<script>
import {getSysmenu} from '../../api/api'
export default {
  data() {
    return {
      collapse: false,
      menuItems: [],
      items: [
        {
          icon: "el-icon-lx-home",
          index: "control",
          title: "工作台"
        },
        {
          icon: "el-icon-lx-cascades",
          index: "table",
          title: "签约管理",
          subs:[
            {
              index:"pending",
              title:"待处理签约"
            },
                        {
              index:"recordsigning",
              title:"签约记录"
            }
          ]
        }, 
        {
          icon: "el-icon-lx-copy",
          index: "1",
          title: "服务管理",
           subs:[
            {
              index:"sginUp",
              title:"待处理服务"
            },
            {
              index:"servicelog",
              title:"服务记录"
            }
          ]
        },
        {
          icon:"el-icon-lx-copy",
          index:"residentManagement",
          title:"居民管理"
        },
         {
          icon:"el-icon-lx-copy",
          index:"massage",
          title:"消息管理"
        },
        {
          icon: "el-icon-lx-calendar",
          index: "2",
          title: "资料管理",
          subs: [
            {
              index: "organizational",
              title: "机构管理"
            },
            {
              index: "team",
              title: "团队管理"
            },
            {
              index: "doctor",
              title: "医生管理"
            },
            {
              index: "service-pack-management",
              title: "服务包管理"
            },
            {
              index: "serviceProject",
              title: "服务项目管理"
            }
          ]
        },
        {
          icon: "el-icon-lx-emoji",
          index: "3",
          title: "数据统计",
          subs:[
            {
              index: "summaryofthedata",
              title: "数据概况"
            },
            {
              index: "contract-data",
              title: "签约业绩统计"
            },
            {
              index: "service-performance-statistics",
              title: "服务业绩统计"
            } 
          ]
        },
        {
          icon: "el-icon-lx-favor",
          index: "4",
          title: "系统设置",
          subs:[
            {
              index: "labelManagement",
              title: "标签管理"
            },
            {
              index: "roleManagement",
              title: "角色管理"
            },
            {
              index: "informationManagement",
              title: "资讯管理"
            }, 
            {
              index: "CarouselManagement",
              title: "轮播图管理"
            },
            {
              index: "systemAffiche",
              title: "系统公告"
            },
            {
              index: "agreementManagement",
              title: "协议管理"
            },
            {
              index: "log",
              title: "操作日志"
            },
            {
              index: "servicePackDetail",
              title: "老人包详情"
            },
            {
              index: "servicePackDetail_two",
              title: "基础包详情"
            },
            {
              index: "servicePackDetail_three",
              title: "基础包详情"
            }
          ]
        },
      ]
    };
  },
  methods: {
    getMenuData(menuName) {
      let menuData = [];
      getSysmenu().then(
        function(data) {
          let data1 = data.data.menuArr;
          data1.forEach((val,index) => {
            let i=8;
            if(val.menuname==menuName){
              let systemItem = {};
              systemItem.icon = "el-icon-setting";
              systemItem.idex=i;
              systemItem.title=val.menuname;
              systemItem.subs=[];
              data1.forEach(value => {
                if(value.parentid==val.id){
                  let systemSubs = {};
                  let menuurl = value.menuurl.split('/')[2];
                  systemSubs.index = menuurl;
                  systemSubs.title = value.menuname;
                  systemItem.subs.push(systemSubs);
                }
              });
              this.items.push(systemItem);
            }
            i++;
          });
        }.bind(this)
      );
    }
  },
  computed: {
    onRoutes() {
      return this.$route.path.replace("/", "");
    }
  },
};
</script>

<style scoped>
.sidebar {
  display: block;
  position: absolute;
  left: 0;
  top: 70px;
  bottom: 0;
  overflow-y: scroll;
}
.sidebar::-webkit-scrollbar {
  width: 0;
}
.sidebar-el-menu:not(.el-menu--collapse) {
  width: 250px;
}
.sidebar > ul {
  height: 100%;
}
</style>
